﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestSystem.Domain.Abstract;
using TestSystem.Domain.DAL;
using TestSystem.Domain.Entities;

namespace TestSystem.Domain.Repositories
{
    public class CategoriesRepository : ICategoryRepository
    {
        private TestSystemContext dbContext = new TestSystemContext();

        public IQueryable<Category> Categories { get {return dbContext.Categories; } }
        public void add(Category entity)
        {
            dbContext.Categories.Add(entity);
            dbContext.SaveChanges();
        }

        public void RemoveCategory(int categoryId)
        {
            dbContext.Categories.Remove(dbContext.Categories.Single(cat => cat.CategoryID.Equals(categoryId)));
            dbContext.SaveChanges();
        }

        public int PositionAmount()
        {
            return dbContext.Categories.Count();
        }
    }
}
